<template>
  <div class="app-container">
    <el-form ref="dataForm" :rules="rules" :model="temp" label-position="left" label-width="190px"
             style="width: 100%; padding: 0 30px;">

      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="退回原因" prop="mhRejectReason">
            <el-input v-model="temp.mhRejectReason"/>
          </el-form-item>
        </el-col>

      </el-row>
    </el-form>
  </div>
</template>

<script>
  import { updateApi, fetchList, approvePlus } from './api'
  // 导入多选项组件
  import SelectOption from '@/views/coding/components/SelectOption'

  export default {
    name: 'Mh-Reject-Reason',

    components: { SelectOption },

    props: {
      isModule: {
        type: Boolean,
        default: false
      },
      row: {}
    },

    data() {
      return {
        // checked: true,
        rules: {
          mhRejectReason: [{ required: true, message: '请输入审核不通过原因', trigger: 'blur' }]
        },
        temp: {},
        dialogVisible: false,
        key: 1
      }
    },

    watch: {
      'row': {
        immediate: true, // vue首次赋值不触发watch的解决方法
        handler: function(nval) {
          if (this.isModule) {
            // this.temp = Object.assign({}, this.row) // copy obj
            if (this.isNull(nval)) {
              return
            }
            if (this.isNull(nval.id)) {
              return
            }
            this.getList(nval.id)
          }
        }
      }
    },

    methods: {

      getList(_id) {
        this.resetTemp()
        fetchList({ id: _id }).then(result => {
          if (!result.success) {
            this.notify(result)
            return
          }
          this.temp = result.map.rows[0]
        })
      },
      // 给外部调用，清空form
      resetTemp() {
        this.temp = {
          mhStatus: '',
          id: undefined
        }

      },
      // 给外部调用，设置默认值，请根据实际情况修改id值
      defaultTemp() {
        this.temp = {
          mhStatus: -1 //设置默认值 一级单位注册状态   '0: 待审核， 1: 审核通过, -1：审核不通过;
        }
      },
      // 树表： 拿当前节点ID作为父节点ID，建立树关系
      setParentNodeId(id) {
        // this.temp.mhProjectInfoId = id
        this.temp.parentId = id
      },
      // 给外部调用,修改记录,状态status 为 1 撤销
      handleApprove(id, mhStatus) {
        this.$confirm('确认提交审核结果吗？')
          .then(_ => {
            approve({ 'id': id, 'mhStatus': mhStatus }).then((r) => {
              this.notify(r)
              if (r.success) {
                this.getList()
              }
            })
            // end
          })
          .catch(_ => {
          })
      },
      withdraw() {

        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$confirm('确认审核不通过吗？').then(_ => {
              const param = { id: this.temp.id }
              //项目状态改为提交
              param.mhStatus = -1
              param.mhRejectReason = this.temp.mhRejectReason
              console.log('param')
              console.log(param)
              approvePlus({ 'id': this.temp.id, 'mhStatus': -1, 'mhRejectReason': this.temp.mhRejectReason }).then((r) => {
                this.notify(r)
                if (r.success) {
                  this.resetTemp()
                  // 从父组件调用此方法，进行回调下
                  if (this.isModule) {
                    this.$emit('withdrawResult')
                  }
                }
              })
              // end
            })
              .catch(_ => {
              })

          }
        })

      },

      // 给外部调用，清除校验
      clearValidate() {
        this.$refs['dataForm'].clearValidate()
      }
    }

  }
</script>
<style>

</style>
